namespace OasisCiq.Xnal
{
    using System.Collections.Generic;
    using System.Collections.Specialized;
    using System.Xml;
    using System.Xml.Schema;
    using System.Xml.Serialization;
    using CommonTypes;
    using External;
    using Xal;
    using Xml;
    using XS;

    /// <summary>
    /// This is a specialised container to combine name and address for postal purposes,
    /// e.g. a label on an envelope that has two parts, an addressee and the address.
    /// </summary>
    public class PostalLabel : 
        IDataQualityGroup, 
        IValidityDateGroup, 
        ILanguageCodeGroup, 
        IExtendedAttributes,
        IXmlSerializable
    {
        private static readonly XmlQualifiedName XmlElementName =
           new XmlQualifiedName("PostalLabel", XmlNamespaces.NameAndAddress);

        public virtual ICollection<Addressee> Addressees { get; set; }

        /// <summary>
        /// Required!
        /// </summary>
        public virtual AddressType Address { get; set; }

        /// <summary>
        /// Status of the entity. e.g. Old, Current, Inactive, Active, etc
        /// </summary>
        public virtual StatusList Status { get; set; }

        public virtual XSDateTime DateValidFrom { get; set; }

        public virtual XSDateTime DateValidTo { get; set; }

        public virtual DataQualityTypeList DataQualityType { get; set; }

        public virtual XSDateTime ValidFrom { get; set; }

        public virtual XSDateTime ValidTo { get; set; }

        public virtual XSLanguage LanguageCode { get; set; }

        public virtual NameValueCollection ExtendedAttributes { get; set; }

        #region IXmlSerializable implementation

        XmlSchema IXmlSerializable.GetSchema()
        {
            return null;
        }

        public virtual void ReadXml(XmlReader reader)
        {
            var wrapper = XmlUtilities.Wrap(reader);
            if (XmlUtilities.MoveToElement(wrapper, XmlElementName))
            {
                new XnalXmlReader(wrapper).ReadPostalLabel(
                    this,
                    XmlElementName.Name,
                    XmlElementName.Namespace);
            }
        }

        public virtual void WriteXml(XmlWriter writer)
        {
            new XnalXmlWriter(writer).WritePostalLabel(this);
        }

        #endregion
    }
}